import global from './config.js'
import request from './request.js'
import tool from './tool.js'
import mixin from './mixin.js'
import update from './update.js'
import store from "./store"

update(global.baseUrl)
const install = Vue => {
	Vue.mixin(mixin) //全局混入
	Vue.prototype.$store = store //全局配置  接口地址等
	Vue.prototype.$global = global //全局配置  接口地址等
	Vue.prototype.$baseUrl = global.baseUrl //接口地址
	Vue.prototype.$request = request //请求逻辑
	Vue.prototype.$tool = tool //工具栏
	Vue.prototype.$navBack = tool.navBack //工具栏
	Vue.prototype.$msg = tool.msg //提示
	Vue.prototype.$showModal = tool.showModal //二次确认框
	Vue.prototype.$refresh = tool.refresh //刷新页面 当前页面onLoad
	Vue.prototype.$log = (e) => console.log(e) //常用于页面视图层log 点击回调参数等

	Vue.prototype.$paths = (paths, num) => { //多图单图处理拼接链接
		let arr = paths
		if (!Array.isArray(paths)) arr = [paths]
		if (num == 1) arr = paths[0]
		return arr
	}

	Vue.prototype.$getCache = (field) => { //读取缓存
		return store.state[field] || uni.getStorageSync(field) || ''
	}

	Vue.prototype.$setCache = (field, data) => { //设置缓存
		store.commit('setData', [field, data])
	}

	Vue.prototype.$goChat = (params) => {
		uni.$u.route('/pages/chat/chat', params)
	}
	Vue.prototype.$text = (fidle) => {
		let obj = {
			identity: {

			}
		}
		return obj[fidle]
	}

	Vue.prototype.$list =function (fidle){
		let rules = {
			name: [{
				required: true,
				message: '请输入名称',
				// blur和change事件触发检验
				trigger: ['blur', 'change'],
			}, ],
			credit_code: [{
				required: true,
				message: '请输入代码',
				// blur和change事件触发检验
				trigger: ['blur', 'change'],
			}, ],
			legal_person: [{
				required: true,
				message: '请输入代表人',
				// blur和change事件触发检验
				trigger: ['blur', 'change'],
			}, ],
			card_no: [{
				required: true,
				message: '请输入身份证号',
				// blur和change事件触发检验
				trigger: ['blur', 'change'],
			}, {
				// 自定义验证函数，见上说明
				validator: (rule, value, callback) => {
					console.log();
					// this.$u.test.mobile()就是返回true或者false的
					return uni.$u.test.idCard(value);
				},
				message: '身份证号不正确',
				// 触发器可以同时用blur和change
				trigger: ['change', 'blur'],
			}],
			card_pros: [{
				required: true,
				message: '请上传身份证',
				// blur和change事件触发检验
				trigger: ['blur', 'change'],
			}, ],
			card_cons: [{
				required: true,
				message: '请上传身份证',
				// blur和change事件触发检验
				trigger: ['blur', 'change'],
			}, ],
			mobile: [{
					required: true,
					message: '请输入手机号',
					// blur和change事件触发检验
					trigger: ['blur', 'change'],
				},
				{
					// 自定义验证函数，见上说明
					validator: (rule, value, callback) => {
						console.log();
						// this.$u.test.mobile()就是返回true或者false的
						return uni.$u.test.mobile(value);
					},
					message: '手机号码不正确',
					// 触发器可以同时用blur和change
					trigger: ['change', 'blur'],
				}
			],
			services: [{
				required: true,
				message: '请选择陪诊项目',
				// blur和change事件触发检验
				trigger: ['blur', 'change'],
			}, ],
			service_year: [{
				required: true,
				message: '请输入护龄',
				// blur和change事件触发检验
				trigger: ['blur', 'change'],
			}, ],
			address: [{
				required: true,
				message: '请输入地址',
				// blur和change事件触发检验
				trigger: ['blur', 'change'],
			}, ],
			certificate: [{
				required: true,
				message: '请上传资格证书',
				// blur和change事件触发检验
				trigger: ['blur', 'change'],
			}, ],
			report: [{
				required: true,
				message: '请上传体检报告',
				// blur和change事件触发检验
				trigger: ['blur', 'change'],
			}, ],
		}

		let identityList = [{
				img: '/static/img/index/pzs.png',
				name: '陪诊师',
				desc: '为患者提供陪诊服务',
				nav: '/pages/index/selectIdentity/accompany',
				identity: 'master'
			},
			// {
			// 	name: '陪诊机构',
			// 	img: '/static/img/index/pzyy.png',
			// 	desc: '为患者提供陪诊服务',
			// 	identity: 'organ',
			// 	nav: '/pages/index/selectIdentity/organization'
			// },
			// {
			// 	name: '司机',
			// 	img: '/static/img/index/sj.png',
			// 	desc: '为患者提供用车服务',
			// 	identity: 'driver'
			// },
		]
		let identity = {
			master: '陪诊师',
			organ: '陪诊机构',
			driver: '司机',
		}
		let sex = {
			0: '未知',
			1: '男',
			2: '女',
		}
		let obj = {
			identityList,
			rules,
			identity,
			sex
		}
		if (fidle) return obj[fidle] || {}
		return obj
	}
}

export default {
	install
}
